package com.gitee.wsl.ext.collection

fun <T : Any> Iterable<T>.findFirstDuplicate(set: Set<T>): Pair<Int, T>? {
    val iter1 = iterator()
    val iter2 = set.iterator()
    var index = 0

    while (iter1.hasNext()) {
        val item = iter1.next()
        if (!iter2.hasNext() || (iter2.next() != item)) {
            return index to item
        }
        index++
    }

    return null
}